import { getToken } from '@/utils/auth'
import { getUserInfo } from '@/api/accountSettings'


const state = {
    token: getToken(),
    userInfo: {}
}

const mutations = {
    SET_USERINFO: (state, userInfo) => {
        state.userInfo = userInfo
    }
}

const actions = {
    getUserInfo({ commit, state }) {
        getUserInfo().then(res => {
            const { data } = res
            commit('SET_USERINFO', data)
            console.log('账户信息', state.userInfo);
        });
        // return new Promise((resolve, reject) => {
        //     getUserInfo(state.token).then(res => {
        //         const { data } = res
        //         commit('SET_USERINFO', data)
        //         console.log('账户信息', state.userInfo);

        //     }).catch(error => {
        //         reject(error)
        //     })
        // })
    },
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
